package com.jgame.secondarymarket.domain.auth.repository;

import com.jgame.secondarymarket.domain.account.repository.AccountRepository;
import com.jgame.secondarymarket.domain.auth.entity.AuthenticAccount;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Component;

import java.util.Optional;

/**
 * @title: AuthenticAccountRepository
 * @Author Wangsj
 * @Date: 2021/7/27
 */
@Component
public class AuthenticAccountRepository {

    @Autowired
    AccountRepository accountRepository;

    public AuthenticAccount findByUsername(String username) {
        return new AuthenticAccount(Optional.ofNullable(accountRepository.findByUserName(username)).orElseThrow(() -> new UsernameNotFoundException("用户" + username + "不存在")));
    }

}
